package com.azusa.xbjy.interceptor;

import com.azusa.xbjy.utils.LoginUserUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(request.getRequestURI());
        //用户为登录则重定向回首页
        if (LoginUserUtil.getLoginUser() == null){
            response.sendRedirect( "/xbjy/index.html");
            return false;
        }
        return true;
    }
}
